package com.cuiweiyou.bluemesh.base;

import android.app.ProgressDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;

import com.cuiweiyou.bluemesh.R;
import com.cuiweiyou.bluemesh.util.CStatusBarUtil;

public class BaseActivity extends AppCompatActivity {
      ProgressDialog progressDialog;

    @Override
    public void setContentView(int layoutResID) {
        super.setContentView(layoutResID);
        initProgressDialog();
        CStatusBarUtil.setWindowStatusBarColor(this, R.color.colorPrimary);
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);// 设置默认键盘不弹出
    }

    private void initProgressDialog(){
        progressDialog = new ProgressDialog(this);
        progressDialog.setCancelable(false); //设置ProgressDialog 是否可以按返回键取消；
        progressDialog.setCanceledOnTouchOutside(false);// 设置在点击Dialog外是否取消Dialog进度条
    }

    public void showProgressDialog(){
        progressDialog.show();
    }

    public void dismissProgressDialog(){
        progressDialog.dismiss();
    }

    /**
     * 显示键盘
     *
     * @param et 输入焦点
     */
    public void showSoftKeyboard(final EditText et) {
        et.requestFocus();
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imm.showSoftInput(et, InputMethodManager.SHOW_IMPLICIT);
    }

    /**
     * 隐藏键盘
     */
    protected void hideSoftKeyboard() {
        InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        View v = getWindow().peekDecorView();
        if (null != v) {
            imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
        }
    }
}


